#include "File.h"
#include <assert.h>
#include "StringUtil.h"
File::File()
{
	m_Check = false;
}

bool File::OpenRead(const std::string& filename)
{
	assert(!m_file.is_open());

	m_file.open(filename);

	assert(m_file.is_open());

	return (m_file.is_open());
}

bool File::EndOf()
{
	if(m_file.eof())
	{
		return true;
	}
	else 
	{
		return false;
	}
}

bool File::GetString(std::string* result)
{
	while(true)
	{
		assert(m_file.is_open());
		if (m_file.eof())
		{
			return false;
		}

		std::getline(m_file, *result);

		if(!m_Check)
		{
			if(result->empty())
			{
				continue;
			}
			if((*result)[0] == '#')
			{
				continue;
			}
			if(result->substr(0, 2) == "/*")
			{
				m_Check = true;
				continue;
			}
			break;
		}

		if(result->substr(0, 2) == "*/")
		{
			m_Check = false;
			continue;
		}
	}
	return true;
}

bool File::GetInteger(int* result)
{
	std::string str;
	if (!(GetString(&str)))
	{
		return false;
	}

	*result = ToInt(str);
	return true;
}

bool File::GetFloat(float* result)
{
	std::string str;
	if (!(GetString(&str)))
	{
		return false;
	}

	*result = ToFloat(str);
	return true;
}